<!-- 会议室管理 -->
<template>
  <app-page card full>
    <app-page-main>
      <template #header>
        <div class="app-query">
          <el-form
            :inline="true"
            :model="pageData.query"
            @submit.prevent="pageActions.handleSearch"
            @keyup.enter="pageActions.handleSearch"
          >
            <el-form-item label="会议室编号">
              <el-input v-model="pageData.query.roomNo" placeholder="请输入" clearable></el-input>
            </el-form-item>
            <el-form-item label="会议室名称">
              <el-input v-model="pageData.query.roomName" placeholder="请输入" clearable></el-input>
            </el-form-item>
            <el-form-item label="会议室位置">
              <el-input v-model="pageData.query.location" placeholder="请输入" clearable></el-input>
            </el-form-item>
            <el-form-item label="可使用状态">
              <el-select
                v-model="pageData.query.isOpen"
                clearable
                :value-on-clear="() => null"
                :empty-values="[null]"
              >
                <el-option label="全部" value=""></el-option>
                <el-option label="开启" value="true"></el-option>
                <el-option label="关闭" value="false"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="search" @click="pageActions.handleSearch">搜索</el-button>
              <el-button icon="refresh" @click="pageActions.handleReset">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="app-action">
          <el-button
            type="primary"
            plain
            icon="plus"
            @click="$router.push({ path: `${$route.path}/edit`, query: { rootPath: $route.path } })"
          >
            添加
          </el-button>
        </div>
      </template>

      <el-table v-loading="pageData.loading" :data="pageData.data">
        <el-table-column type="index" label="序号" width="60" />
        <el-table-column prop="roomNo" label="会议室编号"></el-table-column>
        <el-table-column prop="roomName" label="会议室名称"></el-table-column>
        <el-table-column prop="location" label="会议室位置"></el-table-column>
        <el-table-column label="可使用状态">
          <template #default="{ row }">
            <el-tag :type="row.isOpen ? 'success' : 'danger'">{{ row.isOpen ? '开启' : '关闭' }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="可容纳人数" :formatter="getCapacity"></el-table-column>
        <el-table-column prop="organize" label="平板设备">
          <template #default="{ row }">
            <el-link
              type="primary"
              @click="
                $router.push({
                  path: `${base}/meet/device`,
                  query: { id: row.id, rootPath: $route.path },
                })
              "
            >
              设备列表
            </el-link>
          </template>
        </el-table-column>
        <el-table-column
          prop="desc"
          label="会议室描述"
          :formatter="onFormatter"
          :show-overflow-tooltip="{ popperClass: 'app-table-tooltip' }"
        />
        <el-table-column label="操作">
          <template #default="{ row }">
            <el-button
              link
              type="primary"
              icon="edit"
              @click="
                $router.push({ path: `${$route.path}/edit`, query: { id: row.id, rootPath: $route.path } })
              "
            >
              编辑
            </el-button>
            <el-button link type="primary" icon="delete" @click="pageActions.handleDelete(row)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </app-page-main>

    <template #footer>
      <div class="app-toolbar" v-if="$route.query.from">
        <el-button type="primary" @click="$router.go(-1)">返回</el-button>
      </div>
      <el-pagination
        @size-change="pageActions.handleSizeChange"
        @current-change="pageActions.handlePageChange"
        :current-page="pageData.page"
        :page-size="pageData.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageData.total"
      />
    </template>
  </app-page>
</template>

<script setup>
import { usePageList } from 'jax-node'

const base = import.meta.env.VITE_APP_BASE

const { pageData, pageActions, onFormatter } = usePageList({
  api: 'meet/room',
  query: {
    isOpen: '',
  },
})

const getCapacity = row => {
  return `${row.seats?.length || 0}人`
}
</script>
